# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: inkyu

from datetime import (datetime, time)
from collections import namedtuple

from coin.exchange.kr_rest.product.product_impl import generate_product_from_str2

SymbolInfo = namedtuple('SymbolInfo',
                        ['nickname', 'products', 'sub_req', 'inverse', 'price_multiplier'])


def symbol_info(nickname,
                market_type,
                exchange,
                symbol,
                inverse=False,
                price_multiplier=1.,
                api_version=None,
                trading_dates=None):
  assert trading_dates is not None

  subreq = '%s.%s' % (market_type, exchange)
  if api_version is not None:
    subreq = '%s.%s' % (subreq, api_version)
  return SymbolInfo(
      nickname,
      {
          date: generate_product_from_str2(market_type,
                                           exchange,
                                           api_version,
                                           symbol,
                                           current_datetime=datetime.combine(date, time()))
          for date in trading_dates
      },
      subreq,
      inverse,
      price_multiplier)


def universe_btc(trading_dates):
  return [
      # Futures
      symbol_info('bitflyer-fxbtcjpy',
                  'Futures',
                  'Bitflyer',
                  'BTC-JPY.PERPETUAL',
                  price_multiplier=1. / 108,
                  trading_dates=trading_dates),

      # Futures, inverse
      symbol_info('bitmex-xbtusd',
                  'Futures',
                  'Bitmex',
                  'BTC-USD.PERPETUAL',
                  price_multiplier=1,
                  trading_dates=trading_dates),
      symbol_info('okex-btcusd-perpetual',
                  'Futures',
                  'Okex',
                  'BTC-USD.PERPETUAL',
                  price_multiplier=1,
                  api_version='v3_swap',
                  trading_dates=trading_dates),
      symbol_info('okex-btcusd-quarter',
                  'Futures',
                  'Okex',
                  'BTC-USD.QUARTER',
                  price_multiplier=1,
                  api_version='v3',
                  trading_dates=trading_dates),
      symbol_info('okex-btcusd-nextweek',
                  'Futures',
                  'Okex',
                  'BTC-USD.NEXT_WEEK',
                  price_multiplier=1,
                  api_version='v3',
                  trading_dates=trading_dates),

      # Spot, USD quote
      symbol_info('binance-btcusdt', 'Spot', 'Binance', 'BTC-USDT', trading_dates=trading_dates),

      # Spot, other quote
      symbol_info('upbit-btckrw',
                  'Spot',
                  'Upbit',
                  'BTC-KRW',
                  price_multiplier=1. / 1170,
                  trading_dates=trading_dates),
  ]
